import java.util.*;
import java.util.Map.Entry;

public class test {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Map<String, ArrayList<Integer>> map = new TreeMap<String, ArrayList<Integer>>();
        ArrayList s = new ArrayList();

        int i = 0;
        while (sc.hasNextLine()) {
            String str = sc.nextLine();

            i++;
            if (str.equals("!!!!!")) {
                break;
            } else {
                s.add(str);
                if (str.length() == 0) {
                    continue;
                }

                String[] str1 = str.split(" +");

                for (int j = 0; j < str1.length; j++) {

                    if (map.get(str1[j]) == null) {
                        ArrayList<Integer> line = new ArrayList<Integer>();
                        line.add(i);
                        map.put(str1[j], line);
                    } else {
                        int flag=1;
                        for(int g=0;g<map.get(str1[j]).size();g++){
                            if(map.get(str1[j]).get(g)==i)
                                flag=0;
                        }
                        if(flag==1)
                            map.get(str1[j]).add(i);
                    }
                    map.put(str1[j], map.get(str1[j]));
                }
            }
        }
        Iterator<Map.Entry<String, ArrayList<Integer>>> m = map.entrySet().iterator();
        while (m.hasNext()) {
            Entry<String, ArrayList<Integer>> e = m.next();

            System.out.println(e.getKey() + "=" + e.getValue());

        }

        while(true){

            String str = sc.nextLine();
            String[] str1 = str.split(" ");
            if(str1[0]==null)
                System.out.println("found 0 results");
            else{
                if(map.containsKey(str1[0])==false){
                    System.out.println("found 0 results");
                    continue;
                }
                ArrayList<Integer> a = new ArrayList<Integer>();
                a=map.get(str1[0]);
                int flag=0;
                for(int j=1;j<str1.length;j++){
                    if(map.containsKey(str1[j])==false){
                        flag=1;
                        System.out.println("found 0 results");
                        break;
                    }
                    ArrayList<Integer> b = new ArrayList<Integer>();
                    b=map.get(str1[j]);
                    a.retainAll(b);
                }
                if(flag==1){
                    continue;
                }
                if(a.size()==0){
                    System.out.println("found 0 results");
                    continue;
                }
                else{


                    System.out.println(a);
                    for(int k=0;k<a.size();k++){
                        System.out.println("line "+a.get(k)+":"+s.get(a.get(k)-1));
                    }

                }

            }


        }

    }

}